
$(function(){
	
	var cycle = 1;
	var one = 0;
	
	setInterval(function(){
		
		var nowPage = parseInt($('#save_trigger_value').text());
		var maxPage = parseInt($('#save_trigger_max_value').text());
		
		if(nowPage <= maxPage && cycle <= maxPage){
			one = 0;
			cycle++;
			next_pic();
		}else{
			if(one == 0){
				cycle += maxPage;
				one = 1;
			}
			
			last_pic();
			
			cycle--;
			
			if(cycle == maxPage){
				cycle = 1;
			}
		}
		
	},2000);
	
});

function last_pic(){
	
	var nowPage = parseInt($('#save_trigger_value').text());
	var maxPage = parseInt($('#save_trigger_max_value').text());
	
	if(nowPage >1){
		nowPage = nowPage - 1;
	}else if(nowPage >= maxPage){
		nowPage = maxPage;
	}else{
		return;
	}
	
	var id = '#page_first_home' + nowPage;
	
	$(id).trigger('click');
	$('#save_trigger_value').text(nowPage);
}

function next_pic(){
	
	var nowPage = parseInt($('#save_trigger_value').text());
	var maxPage = parseInt($('#save_trigger_max_value').text());
	
	if(nowPage >0){
		nowPage = nowPage + 1;
	}else if(nowPage >= maxPage){
		nowPage = maxPage;
	}else{
		return;
	}
	
	var id = '#page_first_home' + nowPage;
	
	$(id).trigger('click');
	$('#save_trigger_value').text(nowPage);
	
}


